package financial.sharing.center.invoice.model.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import financial.sharing.center.common.base.BaseEntity;
import financial.sharing.center.common.enums.EnableStatusEnum;
import financial.sharing.center.common.utils.BigDecimalUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @ClassName InvoiceDetail
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/4/12
 * @Version 1.0
 */
@Data
@AllArgsConstructor
@ToString
@Entity
public class InvoiceDetail extends BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    /**发票id*/
    private Integer invoiceId;
    /**发票代码*/
    private String invoiceCode;
    /**发票号码*/
    private String invoiceNumber;
    /**开票日期*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date date;

    /**购方*/
    /**账户id*/
    private Integer buyAccountId;

    /**销方*/
    /**账户id*/
    private Integer sellAccountId;


    /**发票内容*/
    private String invoiceContext;
    /**规格型号*/
    private String specificationModel;
    /**单位*/
    private String unit;
    /**数量*/
    private Integer quantity;
    /**单价*/
    private BigDecimal unitPrice;
    /**金额*/
    private BigDecimal totalMoney;
    /**税率*/
    private Integer taxRateId;
    /**税额 金额 x 税率*/
    @Transient
    private BigDecimal taxMoney;
    /**价税合计 = 金额 + 税额*/
    @Transient
    private BigDecimal totalTaxMoney;
    /**币种*/
    private String currencyDicCode;

    /**备注*/
    private String note;

    /**创建日期*/
    private Date createTime;

    /**可用性*/
    private Integer enableStatusValue;

    public InvoiceDetail() {

    }

    public InvoiceDetail(Integer invoiceId, String invoiceContext) {
        this.invoiceId = invoiceId;
        this.invoiceContext = invoiceContext;
        this.createTime = new Date();
        this.totalMoney = BigDecimalUtil.ZERO;
        this.totalTaxMoney = BigDecimalUtil.ZERO;
        this.taxMoney = BigDecimalUtil.ZERO;
        this.quantity = 0;
        this.unitPrice = BigDecimalUtil.ZERO;
        this.enableStatusValue = EnableStatusEnum.正常.getValue();
    }
}
